#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define ARCHIVO "Alumnos.bin"

typedef struct Alumno
{
    int id;
    char nia[12];
    char provincia[16];
    char nombre[16];
    char apellidos[12];
    float nota;
} Alumno;

Alumno alumnos[] =
{
    {125,"100994091","Valencia","MARCO","MORALES",6.5},
    {233,"100691842","Madrid","CRISTIAN","PEREZ",2.1},
    {12,"100194281","Cuenca","JORGE","GARCIA",6.8},
    {44,"100046076","Guadalajara","CAROLINA","SANTILLANA",6.8},
    {48,"100886999","Toledo","ANTONIO","CRUZ",0.2},
    {91,"100117342","Segovia","ÁLVARO","RIVERA",0},
    {122,"100355305","Ávila","JAIME","CABRERA",5.5},
    {212,"100922125","Soria","ADRIAN","CABRERA",8.8},
    {291,"100433370","Zaragoza","JULIAN","TORRES",8.8},
    {111,"100572200","León","MARIA","HIDALGO",2.8},
    {108,"100358889","Zamora","YOLANDA","PEREZ",6.7},
    {93,"100538832","Salamanca","SERGIO","CANO",6.4},
    {25,"100594287","Pontevedra","JULIAN","SANTILLANA",4.2},
    {88,"100085956","Burgos","MARTA","RAMOS",6.6},
    {0, "","","","",0}

};

int main (void)
{
    printf ("sizeof(Alumno) =%ld\n",sizeof(Alumno));
    printf ("sizeof(Alumnos)=%ld\n",sizeof(alumnos));

    FILE *f = fopen(ARCHIVO,"wb");
    if(!f)
    {
        fprintf(stderr, "At %s, line %d:\n\tERROR: could not open file %s:%s\n",
                __FILE__,
                __LINE__,
                ARCHIVO,
                strerror(errno));
        exit(1);
    }
    fwrite(alumnos,sizeof(Alumno),15,f);

    fclose(f);
}
